﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Midgard
{
    class ArtifactManager
    {
        List<Artifact> artifacts;
        Dictionary<String, List<Texture2D>> animTextures;

        public ArtifactManager()
        {
            artifacts = new List<Artifact>();
            animTextures = new Dictionary<string, List<Texture2D>>();
        }

        public void update(GameTime gameTime)
        {
            for (int i = artifacts.Count - 1; i >= 0; i--)
            {
                artifacts[i].Update();
                //Console.WriteLine(artifacts[i].position.X + ", " + artifacts[i].position.Y);
                if (artifacts[i].Active == false)
                {
                    artifacts.RemoveAt(i);
                }
            }

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach (Artifact a in artifacts)
            {
                a.Draw(spriteBatch);
            }
        }
        public void addTextureSet(String EnemyType, List<Texture2D> Textures)
        {
            Console.WriteLine(EnemyType);
            animTextures.Add(EnemyType, Textures);
        }
        public void addEnemiesHit(List<Enemy> enemies)
        {
            foreach (Enemy e in enemies)
            {
                if (e.Type == EnemyType.THOR)
                {
                       artifacts.Add(new Artifact(animTextures["ThorHurt"], new Vector2(e.Position.X, e.Position.Y + animTextures["ThorHurt"][0].Height/2f), new Vector2(), new Vector2(0,-.01f), 10, 3, 20, 15, e.IsLeft, "ThorHurt"));
                }
            }
        }
        public void addWave()
        {
            artifacts.Add(new Artifact(animTextures["Wave"], new Vector2(600, 0), new Vector2(-50, 0), new Vector2(-25, 5), 10, 1, 25, 5, true, "Wave"));
        }
        public void addEnemiesDeaths(List<Enemy> enemies)
        {
            foreach (Enemy e in enemies)
            {


                if (e.Type == EnemyType.THOR)
                {
                    artifacts.Add(new Artifact(animTextures[e.Type.ToString()], new Vector2(e.Position.X, e.Position.Y - animTextures[e.Type.ToString()][0].Height/2f), new Vector2(0, 0), new Vector2(0, -.25f), 30, 3, 20, 9, e.IsLeft, e.Type.ToString()));
                }
                else if (e.Type != EnemyType.Wizard)
                {
                    float speed = e.Speed / 8;
                    if (e.IsLeft)
                    {
                        speed = speed * -1;
                    }
                    artifacts.Add(new Artifact(animTextures[e.Type.ToString()], e.Position, new Vector2(speed, 0), new Vector2(0, (float)0.05), 25, 4, 20, 15, e.IsLeft, e.Type.ToString()));
                }
                else
                {
                    float speed = e.Speed;
                    if (e.IsLeft)
                    {
                        speed = speed * -1;
                    }
                    artifacts.Add(new Artifact(animTextures[e.Type.ToString()], e.Position, new Vector2(speed, 0), new Vector2(0, (float)0.25), 20, 3, 20, 9, e.IsLeft, e.Type.ToString()));
                }

                e.State = EnemyState.Inactive;
            }
        }
    }

}
